package com.ruoyi.framework.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;
@Service
@Component
public class RedisMessageSubscriber implements MessageListener {

    @Override
    public void onMessage(Message message, byte[] pattern) {
        // 获取消息内容
        String messageBody = new String(message.getBody(), StandardCharsets.UTF_8);
        // 输出到控制台
        System.out.println("Received message(监听到频道号------students------的消息为) " + messageBody);
        System.out.println("-------"+new String(pattern, StandardCharsets.UTF_8)+"---------");


    }
}
